package io.geekidea.springbootplus.system.service.impl;

import io.geekidea.springbootplus.system.entity.EnterApply;
import io.geekidea.springbootplus.system.mapper.EnterApplyMapper;
import io.geekidea.springbootplus.system.service.EnterApplyService;
import io.geekidea.springbootplus.system.param.EnterApplyPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 *  服务实现类
 *
 * @author miko
 * @since 2020-10-10
 */
@Slf4j
@Service
public class EnterApplyServiceImpl extends BaseServiceImpl<EnterApplyMapper, EnterApply> implements EnterApplyService {

    @Autowired
    private EnterApplyMapper enterApplyMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveEnterApply(EnterApply enterApply) throws Exception {
        return super.save(enterApply);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateEnterApply(EnterApply enterApply) throws Exception {
        return super.updateById(enterApply);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteEnterApply(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<EnterApply> getEnterApplyPageList(EnterApplyPageParam enterApplyPageParam) throws Exception {
        Page<EnterApply> page = new PageInfo<>(enterApplyPageParam, OrderItem.desc(getLambdaColumn(EnterApply::getCreateTime)));
        LambdaQueryWrapper<EnterApply> wrapper = new LambdaQueryWrapper<>();
        IPage<EnterApply> iPage = enterApplyMapper.selectPage(page, wrapper);
        return new Paging<EnterApply>(iPage);
    }

}
